def extract_diagnosis_info(lines):
    """
    从病例记录文本中提取入院诊断、死亡诊断和死亡原因

    参数:
    lines -- 包含病例记录的文本行列表

    返回:
    包含提取信息的字典
    """
    # 初始化结果字典
    extracted_info = {
        "入院诊断": "",
        "死亡诊断": "",
        "死亡原因": ""
    }

    # 遍历每一行来查找关键信息
    for line in lines:
        line = str(line).strip()

        # 提取入院诊断
        if line.startswith("入院诊断：") or line.startswith("入院诊断: "):
            extracted_info["入院诊断"] = line.split("：", 1)[1].strip() if "：" in line else line.split(": ", 1)[1].strip()

        # 提取死亡诊断
        elif line.startswith("死亡诊断：") or line.startswith("死亡诊断: "):
            extracted_info["死亡诊断"] = line.split("：", 1)[1].strip() if "：" in line else line.split(": ", 1)[1].strip()

        # 提取死亡原因
        elif line.startswith("死亡原因：") or line.startswith("死亡原因: "):
            extracted_info["死亡原因"] = line.split("：", 1)[1].strip() if "：" in line else line.split(": ", 1)[1].strip()

    return extracted_info

def extract_diagnosis_info_enhanced(lines):
    """
    增强版提取函数，处理可能跨行的诊断信息

    参数:
    lines -- 包含病例记录的文本行列表

    返回:
    包含提取信息的字典
    """
    # 初始化结果字典
    extracted_info = {
        "入院诊断": "",
        "死亡诊断": "",
        "死亡原因": ""
    }

    # 当前正在处理的字段
    current_field = None

    # 遍历每一行来查找关键信息
    for line in lines:
        line = str(line).strip()

        # 检查是否是新的字段开始
        if line.startswith("入院诊断"):
            current_field = "入院诊断"
            # 提取冒号后的内容
            if "：" in line or ": " in line:
                value = line.split("：", 1)[1].strip() if "：" in line else line.split(": ", 1)[1].strip()
                extracted_info[current_field] = value

        elif line.startswith("死亡诊断"):
            current_field = "死亡诊断"
            # 提取冒号后的内容
            if "：" in line or ": " in line:
                value = line.split("：", 1)[1].strip() if "：" in line else line.split(": ", 1)[1].strip()
                extracted_info[current_field] = value

        elif line.startswith("死亡原因"):
            current_field = "死亡原因"
            # 提取冒号后的内容
            if "：" in line or ": " in line:
                value = line.split("：", 1)[1].strip() if "：" in line else line.split(": ", 1)[1].strip()
                extracted_info[current_field] = value

        # 如果当前行不是新字段开始，且存在当前字段，则考虑是否为当前字段的延续
        elif current_field and not any(line.startswith(field) for field in ["入院情况", "诊疗经过", "书写者"]):
            # 仅当行不是其他字段的开始时，才考虑为当前字段的延续
            # 这里假设"入院情况"、"诊疗经过"和"书写者"是可能紧跟在我们关注的字段之后的其他字段
            if not line.startswith("入院") and not line.startswith("死亡") and extracted_info[current_field]:
                extracted_info[current_field] += " " + line

        if '--------------------------------------------------------------------------------' in extracted_info['死亡原因']:
          extracted_info['死亡原因'] = extracted_info['死亡原因'].replace('--------------------------------------------------------------------------------', '')

        if '：' in extracted_info['死亡原因']:
          extracted_info['死亡原因'] = extracted_info['死亡原因'].split('：')[0]

    return extracted_info